supernova: fix boost.thread move semantics
[supercollider.git] / Help / UGens / Playback and Recording / VDiskIn.html
blob1a4efc5511e6e40dda886770353154138b92e8da
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="949.43">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #22407b; min-height: 12.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica; min-height: 17.0px}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
18 p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
19 p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060}
20 span.s1 {color: #3562bb}
21 span.s2 {color: #3867c2}
22 span.s3 {color: #0000bf}
23 span.s4 {color: #606060}
24 span.s5 {color: #000000}
25 span.s6 {color: #007300}
26 span.s7 {color: #bf0000}
27 span.s8 {text-decoration: underline}
28 span.Apple-tab-span {white-space:pre}
29 </style>
30 </head>
31 <body>
32 <p class="p1"><b>VDiskIn<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>stream in audio from a file (with variable rate)</b></p>
33 <p class="p2"><br></p>
34 <p class="p2"><br></p>
35 <p class="p3"><b>VDiskIn.ar(numChannels, bufnum, rate, loop, sendID )</b></p>
36 <p class="p2"><br></p>
37 <p class="p3">Continuously play a longer soundfile from disk.<span class="Apple-converted-space">  </span>This requires a buffer to be preloaded with one buffer size of sound. If loop is set to 1, the soundfile will loop. If a sendID is given, the UGen sends an osc message with this id and the file position each time it reloads the buffer: ['/diskin', nodeID, sendID, frame]<span class="Apple-converted-space"> </span></p>
38 <p class="p4"><br></p>
39 <p class="p3"><b>rate</b> controls the rate of playback. Values below 4 are probably fine, but the higher the value, the more disk activity there is, and the more likelihood there will be a problem.</p>
40 <p class="p4"><br></p>
41 <p class="p3"><b>WARNING:</b> the rate does have a practical limit. The following must be true:<span class="Apple-converted-space"> </span></p>
42 <p class="p3"><span class="Apple-tab-span"> </span>rate<span class="Apple-converted-space">  </span>&lt; Buffer's size / ( 2 * s.options.blockSize)</p>
43 <p class="p3"><span class="Apple-tab-span"> </span>e.g with typical default values, this wil be 32768 / (2 * 64) = 256.</p>
44 <p class="p4"><span class="Apple-tab-span"> </span></p>
45 <p class="p3">If the rate is too high, the UGen will not execute, posting a warning.</p>
46 <p class="p4"><br></p>
47 <p class="p4"><br></p>
48 <p class="p3"><b>See also:</b> <a href="PlayBuf.html"><span class="s1">PlayBuf</span></a>, <a href="../Oscillators/BufRd.html"><span class="s2">BufRd</span></a><span class="Apple-converted-space"> </span></p>
49 <p class="p5"><br></p>
50 <p class="p5"><br></p>
51 <p class="p6"><br></p>
52 <p class="p5"><br></p>
53 <p class="p7"><br></p>
54 <p class="p8">b = <span class="s3">Buffer</span>.cueSoundFile(s, <span class="s4">"sounds/a11wlk01-44_1.aiff"</span>, 0, 1);</p>
55 <p class="p7"><br></p>
56 <p class="p8">x = { <span class="s3">VDiskIn</span>.ar(1, b, <span class="s3">LFNoise2</span>.kr(0.2).range(0.5, 2), 1, loop:1) }.play;</p>
57 <p class="p7"><br></p>
58 <p class="p8">b.close;<span class="Apple-tab-span"> </span></p>
59 <p class="p7"><br></p>
60 <p class="p9">// again</p>
61 <p class="p9">// note the like named instance method, but different arguments</p>
62 <p class="p10"><span class="s5">b.cueSoundFile(</span>"sounds/a11wlk01-44_1.aiff"<span class="s5">, 0);<span class="Apple-tab-span"> </span></span></p>
63 <p class="p7"><span class="Apple-tab-span"> </span></p>
64 <p class="p8">x.free; b.close; b.free;<span class="Apple-tab-span"> </span></p>
65 <p class="p7"><br></p>
66 <p class="p7"><br></p>
67 <p class="p9">// cue and play right away</p>
68 <p class="p8">(</p>
69 <p class="p8"><span class="s3">SynthDef</span>(<span class="s4">"help-VDiskin"</span>, { <span class="s3">arg</span> bufnum = 0;</p>
70 <p class="p8"><span class="Apple-tab-span"> </span><span class="s3">Out</span>.ar(0, <span class="s3">VDiskIn</span>.ar(1, bufnum, <span class="s3">MouseX</span>.kr(0.5, 2.0)));</p>
71 <p class="p8">}).send(s);</p>
72 <p class="p8">)</p>
73 <p class="p8">(</p>
74 <p class="p8">x = <span class="s3">Synth</span>.basicNew(<span class="s4">"help-VDiskin"</span>);</p>
75 <p class="p8">m = { <span class="s3">arg</span> buf; x.addToHeadMsg(<span class="s3">nil</span>, [<span class="s6">\bufnum</span>, buf])};</p>
76 <p class="p7"><br></p>
77 <p class="p8">b = <span class="s3">Buffer</span>.cueSoundFile(s,<span class="s4">"sounds/a11wlk01-44_1.aiff"</span>,0,1, completionMessage: m);</p>
78 <p class="p8">)<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
79 <p class="p7"><br></p>
80 <p class="p8">x.free; b.close; b.free;<span class="Apple-tab-span"> </span><span class="s7">// clean up</span></p>
81 <p class="p7"><br></p>
82 <p class="p7"><br></p>
83 <p class="p7"><br></p>
84 <p class="p7"><br></p>
85 <p class="p9">// sending back the file position.</p>
86 <p class="p9">// note:</p>
87 <p class="p9">// the ugen knows nothing of the loop (apply a modulo).</p>
88 <p class="p9">// if you load another file, you need to free the buffer and re-allocate it (see below)</p>
89 <p class="p7"><br></p>
90 <p class="p8">b = <span class="s3">Buffer</span>.cueSoundFile(s, <span class="s4">"sounds/a11wlk01-44_1.aiff"</span>, 0, 1, bufferSize: 4096);</p>
91 <p class="p10"><span class="s5">c = </span><span class="s3">SoundFile</span><span class="s5">(</span>"sounds/a11wlk01-44_1.aiff"<span class="s5">).info;</span></p>
92 <p class="p8">x = { <span class="s3">VDiskIn</span>.ar(1, b, <span class="s3">LFNoise2</span>.kr(0.2).range(0.2, 0.9), 1, sendID: 14) }.play;</p>
93 <p class="p7"><br></p>
94 <p class="p9">// register to receive this message</p>
95 <p class="p7"><br></p>
96 <p class="p8">(</p>
97 <p class="p8">o = <span class="s3">OSCresponder</span>(s.addr,<span class="s6">'/diskin'</span>,{ <span class="s3">arg</span> time,responder,msg;</p>
98 <p class="p8"><span class="Apple-tab-span"> </span><span class="s3">var</span> sendID = msg[2];</p>
99 <p class="p8"><span class="Apple-tab-span"> </span><span class="s3">var</span> index = msg[3];</p>
100 <p class="p8"><span class="Apple-tab-span"> </span>msg.postln;</p>
101 <p class="p10"><span class="s5"><span class="Apple-tab-span"> </span></span>"id: % pos: % frames (% sec)\n"</p>
102 <p class="p8"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>.postf(sendID, index % c.numFrames, (index % c.numFrames / c.sampleRate));</p>
103 <p class="p8">}).add</p>
104 <p class="p8">);</p>
105 <p class="p7"><br></p>
106 <p class="p8">b.close; b.free;</p>
107 <p class="p7"><br></p>
108 <p class="p10"><span class="s5">b.alloc; b.cueSoundFile(</span>"sounds/a11wlk01-44_1.aiff"<span class="s5">, 0); c = </span><span class="s3">SoundFile</span><span class="s5">(</span>"sounds/a11wlk01-44_1.aiff"<span class="s5">).info;</span></p>
109 <p class="p7"><br></p>
110 <p class="p8">x.free; b.close; b.free; o.remove; <span class="s7">// clean up eventually</span></p>
111 <p class="p7"><br></p>
112 <p class="p7"><br></p>
113 <p class="p7"><br></p>
114 <p class="p7"><br></p>
115 <p class="p7"><br></p>
116 <p class="p7"><br></p>
117 <p class="p9">// the same example in OSC Messaging style, see [<span class="s8">Node Messaging</span>]</p>
118 <p class="p7"><br></p>
119 <p class="p9">// allocate a disk i/o buffer</p>
120 <p class="p8">s.sendMsg(<span class="s4">"/b_alloc"</span>, 0, 65536, 1);</p>
121 <p class="p7"><br></p>
122 <p class="p9">// open an input file for this buffer, leave it open</p>
123 <p class="p10"><span class="s5">s.sendMsg(</span>"/b_read"<span class="s5">, 0, </span>"sounds/a11wlk01-44_1.aiff"<span class="s5">, 0, 65536, 0, 1);</span></p>
124 <p class="p7"><br></p>
125 <p class="p9">// create a diskin node</p>
126 <p class="p8">s.sendMsg(<span class="s4">"/s_new"</span>, <span class="s4">"help-VDiskin"</span>, x = s.nextNodeID, 1, 1);</p>
127 <p class="p7"><br></p>
128 <p class="p9"><span class="s5">s.sendMsg(</span><span class="s4">"/b_close"</span><span class="s5">, 0); </span>// close the file (very important!)</p>
129 <p class="p7"><br></p>
130 <p class="p7"><br></p>
131 <p class="p9">// again<span class="Apple-converted-space"> </span></p>
132 <p class="p9">// don't need to reallocate and Synth is still reading</p>
133 <p class="p10"><span class="s5">s.sendMsg(</span>"/b_read"<span class="s5">, 0, </span>"sounds/a11wlk01-44_1.aiff"<span class="s5">, 0, 0, 0, 1);</span></p>
134 <p class="p7"><br></p>
135 <p class="p8">s.sendMsg(<span class="s4">"/n_free"</span>, x); <span class="s7">// stop reading</span></p>
136 <p class="p7"><br></p>
137 <p class="p9"><span class="s5">s.sendMsg(</span><span class="s4">"/b_close"</span><span class="s5">, 0); </span>// close the file.</p>
138 <p class="p7"><br></p>
139 <p class="p9"><span class="s5">s.sendMsg(</span><span class="s4">"/b_free"</span><span class="s5">, 0); </span>// frees the buffer</p>
140 <p class="p7"><br></p>
141 </body>
142 </html>